import asyncio
from lib.net import wifi


def init():
    # 检查当前网络状态和网络模式
    if not wifi.is_connected():
        print("wifi not connected")
        wifi.do_connect_wifi()


async def run():
    from lib.websocket import action
    from lib.config.index import websocket_config

    await action.connect()

    while True:
        try:
            print(1)
            await action.heart_beat()
            data = await action.read()
            # print("ws recv:", data)
            await asyncio.sleep(websocket_config.get_interval())
        except Exception as e:
            print(e)


init()
asyncio.run(run())
